Skip to content

Python: Fix structured value parsing for split text chunks#6990

Merged
moonbox3 merged 4 commits into
microsoft:mainfrom
t-anjan:fix/structured-output-value-chunks
Jul 14, 2026
Merged

Python: Fix structured value parsing for split text chunks#6990
moonbox3 merged 4 commits into
microsoft:mainfrom
t-anjan:fix/structured-output-value-chunks

Conversation

@t-anjan

@t-anjan t-anjan commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Structured response parsing currently uses the public text property, which inserts spaces between TextContent chunks inside a Message. That can corrupt split JSON structured outputs while leaving normal display text behavior correct.

This change keeps Message.text unchanged and uses a structured-output-only text path that concatenates text chunks without synthetic spaces before parsing ChatResponse.value and AgentResponse.value.

Tests:

  • cd python && uv run pytest packages/core/tests/core/test_types.py
  • cd python && uv run ruff check packages/core/agent_framework/_types.py packages/core/tests/core/test_types.py
  • git diff --check

Copilot AI review requested due to automatic review settings July 8, 2026 09:11
@giles17 giles17 added the python Usage: [Issues, PRs], Target: Python label Jul 8, 2026
@github-actions github-actions Bot changed the title Fix structured value parsing for split text chunks Python: Fix structured value parsing for split text chunks Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes structured-output parsing for ChatResponse.value and AgentResponse.value by avoiding the synthetic spaces introduced by Message.text when a message contains multiple text Content chunks (which can corrupt split JSON). The public Message.text/Response.text behavior remains unchanged for display.

Changes:

  • Added structured-output-only text assembly helpers that concatenate text chunks without inserting spaces.
  • Updated ChatResponse.value and AgentResponse.value to parse structured output from the structured-only text path instead of self.text.
  • Added regression tests covering split JSON across text chunks while preserving Message.text spacing behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/packages/core/agent_framework/_types.py Adds structured-only text helpers and switches structured parsing to use them (avoids Message.text synthetic spacing).
python/packages/core/tests/core/test_types.py Adds tests ensuring split structured JSON parses correctly without changing Message.text/response.text.

Comment thread python/packages/core/agent_framework/_types.py Outdated
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _types.py12269792%61, 70–71, 125, 130, 149, 151, 155, 159, 161, 163, 165, 183, 187, 213, 235, 240, 245, 249, 279, 705–706, 887–888, 1346, 1421, 1456, 1476, 1486, 1538, 1672–1674, 1959–1964, 1989, 2044, 2049, 2059, 2067, 2074–2078, 2096, 2169, 2182, 2187, 2300, 2323, 2584, 2608, 2707, 2888–2889, 2991, 3220, 3273, 3292, 3331, 3342, 3344–3348, 3350, 3353–3361, 3371, 3460, 3597, 3602, 3607, 3612, 3616, 3702–3704, 3733, 3821–3825
TOTAL44418524388% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8959 33 💤 0 ❌ 0 🔥 2m 32s ⏱️

@moonbox3 moonbox3 requested a review from eavanvalkenburg July 8, 2026 09:44
t-anjan and others added 3 commits July 8, 2026 15:17
@t-anjan t-anjan force-pushed the fix/structured-output-value-chunks branch from 98dc0f1 to a5f64d6 Compare July 8, 2026 09:48
@moonbox3

Copy link
Copy Markdown
Contributor

Could you please resolve the conflicts?

@t-anjan

t-anjan commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the conflicts with current main in _types.py and test_types.py.

Upstream changed structured-output parsing to use the final non-empty assistant message, while this PR fixes parsing of structured JSON split across multiple text content chunks (without the spaces inserted by Message.text). The resolution keeps upstream’s final-message selection and makes that helper concatenate the selected message’s raw text chunks directly. I retained regression coverage for both behaviors; uv run --directory packages/core pytest tests/core/test_types.py -q passes all 278 tests.

@moonbox3 moonbox3 enabled auto-merge July 14, 2026 08:32
@moonbox3 moonbox3 added this pull request to the merge queue Jul 14, 2026
Merged via the queue into microsoft:main with commit 1c00827 Jul 14, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants